import request from "@/utils/request";
import Qs from "qs";

//运营管理

export function queryAll(currentPage, pageSize) {
    return new Promise((resolve, reject) => {
        request.get("purchase/queryAll", {
            params: {
                currentPage,
                pageSize
            }
        }).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}


export function insert(title, product, supplier, tel, signingTime, state, manager) {
    return new Promise((resolve, reject) => {
        request.post("purchase/insert", Qs.stringify({
            title,
            product,
            supplier,
            tel,
            signingTime,
            state,
            manager
        })).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function queryById(id) {
    return new Promise((resolve, reject) => {
        request.get("purchase/queryOne", {
            params: {
                id
            }
        }).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function update(id, title, product, supplier, tel, signingTime, state, manager) {
    return new Promise((resolve, reject) => {
        request.post("purchase/update", Qs.stringify({
            id,
            title,
            product,
            supplier,
            tel,
            signingTime,
            state,
            manager
        })).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function deleteP(id) {
    return new Promise((resolve, reject) => {
        request.delete("purchase/delete/" + id).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function productQueryAll(currentPage, pageSize) {
    return new Promise((resolve, reject) => {
        request.get("product/queryAll", {
            params: {
                currentPage, pageSize
            }
        }).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function deleteProduct(id) {
    return new Promise((resolve, reject) => {
        request.delete("product/delete/" + id).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function getProductById(id) {
    return new Promise((resolve, reject) => {
        request.get("product/get/" + id).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function updateProduct(id,
                              product,
                              manufacturer,
                              inventory,
                              money,
                              state,) {
    return new Promise((resolve, reject) => {
        request.post("product/update/", Qs.stringify({
            id,
            product,
            manufacturer,
            inventory,
            money,
            state
        })).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function addProduct(product,
                           manufacturer,
                           inventory,
                           money,
                           state,) {
    return new Promise((resolve, reject) => {
        request.post("product/insert", Qs.stringify({
            product,
            manufacturer,
            inventory,
            money,
            state
        })).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function productHadoop() {
    return new Promise((resolve, reject) => {
        request.get("product/getHadoop/").then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function getMarketView() {
    return new Promise((resolve, reject) => {
        request.get("product/getMarketView").then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

//财务
export function getCaiWuHadoop() {
    return new Promise((resolve, reject) => {
        request.get("finance/hadoop").then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

export function caiWuQueryAll(currentPage, pageSize) {
    return new Promise((resolve, reject) => {
        request.get("finance/get/all", {
            params: {
                currentPage, pageSize
            }
        }).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}

/**
 *
 * @param type
 * @param title
 * @param fDesc
 * @param fIn
 * @param fOut
 * @param time
 * @returns {Promise<unknown>}
 */
export function addCaiWu(type,
                         title,
                         fDesc,
                         fIn,
                         fOut,
                         time,) {
    return new Promise((resolve, reject) => {
        request.post("finance/insert", Qs.stringify({
            type,
            title,
            fDesc,
            fIn,
            fOut,
            time,
        })).then(resp => {
            resolve(resp.data)
        }).catch(error => {
            reject(error)
        })
    });
}


